import request from '@/utils/request'
import type { ResponseData } from '@/types/common'
import type { Dress, DressQuery } from '@/types/dress'

// 获取婚纱列表
export const getDresses = (params?: {
  keyword?: string
  category?: number
  style?: string
  status?: number
  minPrice?: number
  maxPrice?: number
  page?: number
  pageSize?: number
}) => {
  return request.get<{
    code: number
    data: {
      items: Dress[]
      meta: {
        total: number
        page: number
        pageSize: number
        totalPage: number
      }
    }
    message: string
  }>('/dresses/list', {
    params: {
      keyword: params?.keyword || '',
      category: params?.category,
      style: params?.style,
      status: params?.status,
      minPrice: params?.minPrice,
      maxPrice: params?.maxPrice,
      page: params?.page || 1,
      pageSize: params?.pageSize || 10,
    },
  })
}

// 创建婚纱
export const createDress = (data: {
  name: string
  category: number
  styles: string[]
  sizes: string[]
  colors: string[]
  price: number
  deposit: number
  description: string
}) => {
  return request.post<ResponseData>('/dresses', data)
}

// 获取婚纱详情
export const getDressDetail = (id: number) => {
  return request.get<{
    code: number
    data: Dress
    message: string
  }>(`/dresses/${id}/detail`)
}

// 更新婚纱信息
export const updateDress = (
  id: number,
  data: {
    name?: string
    category?: number
    styles?: string[]
    sizes?: string[]
    colors?: string[]
    price?: number
    deposit?: number
    description?: string
  },
) => {
  return request.patch<ResponseData>(`/dresses/${id}/update`, data)
}

// 更新婚纱照片
export const updateDressPhotos = (id: number, data: { photos: string[] }) => {
  return request.patch<ResponseData>(`/dresses/${id}/photos`, data)
}

// 切换婚纱状态(上架/下架)
export const updateDressStatus = (id: number) => {
  return request.patch<ResponseData>(`/dresses/${id}/status`)
}

// 更新婚纱租赁状态
export const updateDressRentStatus = (id: number, status: number) => {
  return request.patch<ResponseData>(`/dresses/${id}/rent-status`, { status })
}

// 删除婚纱
export const deleteDress = (id: number) => {
  return request.delete<ResponseData>(`/dresses/${id}`)
}
